 //108.将有序数组转换为一又搜索树
 //https://leetcode.cn/problems/convert-sorted-array-to-binary-search-tree/
class Solution {
public:
    TreeNode* sortedArrayToBST(vector<int>& nums) {
        //二分
        return dfs(nums,0,nums.size()-1);
    }

    TreeNode* dfs(vector<int>& nums, int l, int r)
    {
        if(l > r) return nullptr;
        int mid = (l+r)/2;
        TreeNode* root = new TreeNode(nums[mid]);
        root->left = dfs(nums,l,mid-1);
        root->right = dfs(nums,mid+1,r);
        return root;
    }
};